package com.fjec.market.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fjec.market.entity.BizPhysicalOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 041.实物订单表 Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2020-09-21
 */
@Mapper
public interface BizPhysicalOrderMapper extends BaseMapper<BizPhysicalOrder> {

    /**
     * 根据订单状态获取用户订单列表
     *
     * @param page
     * @param userId
     * @param status
     * @return
     */
    Page<Map<String, Object>> getOrderByUserIdAndStatus(Page page,
                                                        @Param("userId") Long userId,
                                                        @Param("status") Integer status);


    /**
     * 根据订单状态获取用户订单列表
     *
     * @param page
     * @param busiId
     * @param busiType
     * @return
     */
    Page<Map<String, Object>> getOrderByBusiIdAndBusiType(Page page,
                                                          @Param("busiId") Long busiId,
                                                          @Param("busiType") Integer busiType,
                                                          @Param("status") Integer status);


    /**
     * 根据Id获取订单详情
     *
     * @param id
     * @return
     */
    Map<String, Object> getSubOrderDetailById(@Param("id") Long id);

    /**
     * 根据子订单Id获取相同主订单其他订单信息
     *
     * @param id
     * @param subId
     * @return
     */
    List<Map<String, Object>> getSameSubOrderByOrderId(@Param("id") Long id,
                                                       @Param("subId") Long subId);

    List<Map<String, Object>> getOrderByConditions(@Param("searchBy") Integer searchBy,
                                                   @Param("title") String title,
                                                   @Param("busiType") Integer busiType,
                                                   @Param("markCode") Integer markCode,
                                                   @Param("orderType") Integer orderType,
                                                   @Param("orderStatus") Integer orderStatus,
                                                   @Param("startTime") LocalDateTime startTime,
                                                   @Param("endTime") LocalDateTime endTime,
                                                   @Param("page") Page page);

    Map<String, Object> getOrderDetailById(Long id);

    /**
     * 获取超时订单
     *
     * @param limit
     * @param minutes
     * @return
     */
    List<Long> getTimeoutOrder(int limit, int minutes);

    List<Map<String, Object>> getSubOrdersByBusiId(Long busiId, Page page);

    // todo: 完善sql
    List<Map<String, Object>> getTradingsByConditions(Integer searchBy, String title, Integer orderType, Integer sellerType, Integer buyerType, Page page);

    List<Map<String, Object>> getOrderComplaintsByConditions(Integer searchBy, String title, Integer busiType, Integer markCode, Integer orderType, Integer orderStatus, LocalDateTime startTime, LocalDateTime endTime, Page page);

    Long getSellerUserIdByOrderId(@Param("orderId") Long orderId);

    List<Map<String, Object>> getLongTimeUndeliveredOrders(@Param("remindTime") Integer remindTime);

    List<Map<String, Object>> getOrdersToDivide(@Param("limit") int limit, @Param("minutes") int minutes);

    List<Long> getLongTimeUnsignedSubOrders(@Param("limit") int limit, @Param("days") int days);

    List<Map<String, Object>> getAutoRefundSubOrders(@Param("limit") int limit, @Param("autoRefundHours") Integer autoRefundHours);

    List<Map<String, Object>> getDeliveredOrdersToSyncYs(@Param("limit") int limit);

    List<Map<String, Object>> getSignedOrdersToSyncYs(@Param("limit") int limit);

    /**
     * 搜索早餐店铺订单信息
     *
     * @param page
     * @param shopId      早餐店铺Id
     * @param subOrderId  子订单Id
     * @param busiType    早餐店铺类型
     * @param orderType   订单类型
     * @param orderStatus 订单状态
     * @param startTime   开始时间
     * @param endTime     结束时间
     * @return
     */
    Page<Map<String, Object>> getOrderForBreakfast(@Param("page") Page page,
                                                   @Param("shopId") Long shopId,
                                                   @Param("subOrderId") Long subOrderId,
                                                   @Param("busiType") Integer busiType,
                                                   @Param("orderType") Integer orderType,
                                                   @Param("orderStatus") Integer orderStatus,
                                                   @Param("startTime") LocalDateTime startTime,
                                                   @Param("endTime") LocalDateTime endTime);

    /**
     * 查询早餐店铺订单信息，生成excel用
     *
     * @param shopId
     * @param busiType
     * @param startTime
     * @param endTime
     * @return
     */
    List<Map<String, Object>> getOrderForBreakfastExcel(@Param("shopId") Long shopId,
                                                        @Param("busiType") Integer busiType,
                                                        @Param("startTime") LocalDateTime startTime,
                                                        @Param("endTime") LocalDateTime endTime);
}
